<?php

namespace app\cps\controller;

use app\cps\service\StatisticsService;
use think\facade\Request;
use app\common\Common;
// use think\facade\Session;
use think\facade\View;

class Index extends Base
{
    private $service;

    public function __construct(StatisticsService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染页面公共部分
    public function index()
    {
        return view();
    }

    // 渲染订单统计首页
    public function statistics()
    {
        return view();
    }

    // 切换公众号
    public function switchOfficialAccount()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Login::class)->scene('update_official_account')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->updateUsedOfficialAccount($params['official_account_id'], $this->getUserInfo());

        if (!$result) {
            return Common::fail();
        }
        return Common::success($result);
    }

    // 订单统计
    public function orderStatistics()
    {
        $params = Request::param();
        $data = $this->service->getOrderStatisticsData($params, $this->getUserInfo());
        return Common::success($data);
    }

    // 近7日充值统计
    public function rechargeStatistics()
    {
        $data = $this->service->getRechargeStatisticsData($this->getUserInfo());
        return Common::success($data);
    }

    // 短剧统计
    public function videoStatistics()
    {
        $data = $this->service->getVideoStatisticsData($this->getUserInfo());
        return Common::success($data);
    }

    // 短剧统计列表
    public function videoStatisticsList()
    {
        $params = Request::param();
        $data = $this->service->getVideoStatisticsListData($params, $this->getUserInfo());
        return Common::success($data);
    }

    // 渲染短剧统计页
    public function videoIndex()
    {
        return view();
    }
}